<!DOCTYPE html>

































































<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" />
<title>Action Bar | Android Developers</title>
<link href="../../../assets/android-developer-docs-devguide.css" rel="stylesheet" type="text/css" />
<script src="../../../assets/search_autocomplete.js" type="text/javascript"></script>
<script src="../../../assets/jquery-resizable.min.js" type="text/javascript"></script>
<script src="../../../assets/android-developer-docs.js" type="text/javascript"></script>
<script src="../../../assets/prettify.js" type="text/javascript"></script>
<script type="text/javascript">
  setToRoot("../../../");
</script>
<noscript>
  <style type="text/css">
    html,body{overflow:auto;}
    #body-content{position:relative; top:0;}
    #doc-content{overflow:visible;border-left:3px solid #666;}
    #side-nav{padding:0;}
    #side-nav .toggle-list ul {display:block;}
    #resize-packages-nav{border-bottom:3px solid #666;}
  </style>
</noscript>
</head>
<body class="gc-documentation">

  <div id="header">
      <div id="headerLeft">
          <a href="../../../index.html" tabindex="-1"><img
              src="../../../assets/images/bg_logo.png" alt="Android Developers" /></a>
          <ul id="header-tabs" class="guide">
    
	<li id="home-link"><a href="../../../offline.html">
	
		<span class="en">Home</span>
		<span style="display:none" class="de">Startseite</span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ホーム</span>
		<span style="display:none" class="zh-CN">主页</span>
		<span style="display:none" class="zh-TW">首頁</span>
	
	</a></li>
	<li id="sdk-link"><a href="../../../sdk/index.html">
		<span class="en">SDK</span>
	</a></li>
	<li id="guide-link"><a href="../../../guide/index.html" onClick="return loadLast('guide')">
	
		<span class="en">Dev Guide</span>
		<span style="display:none" class="de">Handbuch</span>
		<span style="display:none" class="es">Guía</span>
		<span style="display:none" class="fr">Guide</span>
		<span style="display:none" class="it">Guida</span>
		<span style="display:none" class="ja">開発ガイド</span>
		<span style="display:none" class="zh-CN">开发人员指南</span>
		<span style="display:none" class="zh-TW">開發指南</span>
	
	</a></li>
	<li id="reference-link"><a href="../../../reference/packages.html" onClick="return loadLast('reference')">
	
		<span class="en">Reference</span>
		<span style="display:none" class="de">Referenz</span>
		<span style="display:none" class="es">Referencia</span>
		<span style="display:none" class="fr">Référence</span>
		<span style="display:none" class="it">Riferimento</span>
		<span style="display:none" class="ja">リファレンス</span>
		<span style="display:none" class="zh-CN">参考</span>
		<span style="display:none" class="zh-TW">參考資料</span>
	
	</a></li>
	<li id="resources-link"><a href="../../../resources/index.html" onClick="return loadLast('resources')">
	
		<span class="en">Resources</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
    		<span style="display:none" class="ja"></span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li id="videos-link"><a href="../../../videos/index.html" onClick="return loadLast('videos')">
	
		<span class="en">Videos</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ビデオ</span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li><a href="http://android-developers.blogspot.com" onClick="return requestAppendHL(this.href)">
	
		<span class="en">Blog</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ブログ</span>
		<span style="display:none" class="zh-CN">博客</span>
		<span style="display:none" class="zh-TW">網誌</span>
	
	</a></li>


     
</ul>
     
      </div>
      <div id="headerRight">
          <div id="headerLinks">
          
          <a href="http://www.android.com">Android.com</a>
          </div>
  <div id="search" >
      <div id="searchForm">
          <form accept-charset="utf-8" class="gsc-search-box" 
                onsubmit="return submit_search()">
            <table class="gsc-search-box" cellpadding="0" cellspacing="0"><tbody>
                <tr>
                  <td class="gsc-input">
                    <input id="search_autocomplete" class="gsc-input" type="text" size="33" autocomplete="off"
                      title="search developer docs" name="q"
                      value="search developer docs"
                      onFocus="search_focus_changed(this, true)"
                      onBlur="search_focus_changed(this, false)"
                      onkeydown="return search_changed(event, true, '../../../')"
                      onkeyup="return search_changed(event, false, '../../../')" />
                  <div id="search_filtered_div" class="no-display">
                      <table id="search_filtered" cellspacing=0>
                      </table>
                  </div>
                  </td>
                  <td class="gsc-search-button">
                    <input type="submit" value="Search" title="search" id="search-button" class="gsc-search-button" />
                  </td>
                  <td class="gsc-clear-button">
                    <div title="clear results" class="gsc-clear-button">&nbsp;</div>
                  </td>
                </tr></tbody>
              </table>
          </form>
      </div><!-- searchForm -->
  </div><!-- search -->
      </div><!-- headerRight -->
      <script type="text/javascript">
        <!--  
        changeTabLang(getLangPref());
        //-->
      </script>
  </div><!-- header -->

  <div class="g-section g-tpl-240" id="body-content">
    <div class="g-unit g-first" id="side-nav">
      <div id="devdoc-nav">
<ul>

  <li>
    <h2><span class="en">Android Basics</span>
        <span class="de" style="display:none">Einführung in Android</span>
        <span class="es" style="display:none">Información básica sobre Android</span>
        <span class="fr" style="display:none">Présentation d'Android</span>
        <span class="it" style="display:none">Nozioni di base su Android</span>
        <span class="ja" style="display:none">Android の基本</span>
        <span class="zh-CN" style="display:none">Android 基础知识</span>
        <span class="zh-TW" style="display:none">Android 簡介</span>
    </h2>
    <ul>
      <li><a href="../../../guide/basics/what-is-android.html">
        <span class="en">What Is Android?</span>
        <span class="de" style="display:none">Was ist Android?</span>
        <span class="es" style="display:none">¿Qué es Android?</span>
        <span class="fr" style="display:none">Qu'est-ce qu'Android&nbsp;?</span>
        <span class="it" style="display:none">Che cos'è Android?</span>
        <span class="ja" style="display:none">Android とは</span>
        <span class="zh-CN" style="display:none">Android 是什么？</span>
        <span class="zh-TW" style="display:none">什麼是 Android？</span>
          </a></li>
      <li><a href="../../../guide/topics/fundamentals.html">
        <span class="en">Application Fundamentals</span>
        <span class="de" style="display:none">Anwendungsgrundlagen</span>
        <span class="es" style="display:none">Fundamentos de las aplicaciones</span>
        <span class="fr" style="display:none">Principes de base des applications</span>
        <span class="it" style="display:none">Concetti fondamentali sulle applicazioni</span>
        <span class="ja" style="display:none">開発の基礎</span>
        <span class="zh-CN" style="display:none">应用程序基础</span>
        <span class="zh-TW" style="display:none">應用程式基本原理</span>
      </a></li>

  <!--  <li><a style="color:gray;">The Android SDK</a></li> -->
  <!--  <li><a style="color:gray;">Walkthrough for Developers</a></li> -->
      <!-- quick overview of what it's like to develop on Android -->
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Framework Topics</span>
      <span class="de" style="display:none">Framework-Themen</span>
      <span class="es" style="display:none">Temas sobre el framework</span>
      <span class="fr" style="display:none">Thèmes relatifs au framework</span>
      <span class="it" style="display:none">Argomenti relativi al framework</span>
      <span class="ja" style="display:none">フレームワーク トピック</span>
      <span class="zh-CN" style="display:none">框架主题</span>
      <span class="zh-TW" style="display:none">架構主題</span>
    </h2>
    <ul>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/fundamentals/activities.html">
          <span class="en">Activities</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/fundamentals/fragments.html">
            <span class="en">Fragments</span>
          </a></li>
          <li><a href="../../../guide/topics/fundamentals/loaders.html">
            <span class="en">Loaders</span>
          </a></li>
          <li><a href="../../../guide/topics/fundamentals/tasks-and-back-stack.html">
            <span class="en">Tasks and Back Stack</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/fundamentals/services.html">
          <span class="en">Services</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/fundamentals/bound-services.html">
            <span class="en">Bound Services</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/topics/providers/content-providers.html">
            <span class="en">Content Providers</span>
          </a></li>
      <li><a href="../../../guide/topics/intents/intents-filters.html">
            <span class="en">Intents and Intent Filters</span>
          </a></li>
      <li><a href="../../../guide/topics/fundamentals/processes-and-threads.html">
            <span class="en">Processes and Threads</span>
          </a></li>
    </ul>


    <ul>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/ui/index.html">
            <span class="en">User Interface</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/topics/ui/declaring-layout.html">
               <span class="en">XML Layouts</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/ui-events.html">
                <span class="en">Input Events</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/menus.html">
               <span class="en">Menus</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/actionbar.html">
               <span class="en">Action Bar</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/dialogs.html">
                <span class="en">Dialogs</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/topics/ui/notifiers/index.html">
                <span class="en">Notifications</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/topics/ui/notifiers/toasts.html">
                <span class="en">Toast Notifications</span>
              </a></li>
              <li><a href="../../../guide/topics/ui/notifiers/notifications.html">
                <span class="en">Status Bar Notifications</span>
              </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/topics/ui/drag-drop.html">
                <span class="en">Drag and Drop</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/themes.html">
                <span class="en">Styles and Themes</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/custom-components.html">
                <span class="en">Custom Components</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/binding.html">
                <span class="en">Binding to Data with AdapterView</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/layout-objects.html">
                <span class="en">Common Layout Objects</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/how-android-draws.html">
                <span class="en">How Android Draws Views</span>
              </a></li>
        </ul>
      </li><!-- end of User Interface -->

      <li class="toggle-list">
        <div><a href="../../../guide/topics/resources/index.html">
               <span class="en">Application Resources</span>
             </a></div>
        <ul>
          <li><a href="../../../guide/topics/resources/providing-resources.html">
                <span class="en">Providing Resources</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/accessing-resources.html">
                <span class="en">Accessing Resources</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/runtime-changes.html">
                <span class="en">Handling Runtime Changes</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/localization.html">
                <span class="en">Localization</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/topics/resources/available-resources.html">
              <span class="en">Resource Types</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/topics/resources/animation-resource.html">Animation</a></li>
              <li><a href="../../../guide/topics/resources/color-list-resource.html">Color State List</a></li>
              <li><a href="../../../guide/topics/resources/drawable-resource.html">Drawable</a></li>
              <li><a href="../../../guide/topics/resources/layout-resource.html">Layout</a></li>
              <li><a href="../../../guide/topics/resources/menu-resource.html">Menu</a></li>
              <li><a href="../../../guide/topics/resources/string-resource.html">String</a></li>
              <li><a href="../../../guide/topics/resources/style-resource.html">Style</a></li>
              <li><a href="../../../guide/topics/resources/more-resources.html">More Types</a></li>
            </ul>
          </li><!-- end of resource types -->
        </ul>
      </li><!-- end of app resources -->
      <li class="toggle-list">
        <div><a href="../../../guide/topics/data/data-storage.html">
            <span class="en">Data Storage</span>
          </a></div>
          <ul>
            <li><a href="../../../guide/topics/data/backup.html">
                <span class="en">Data Backup</span>
              </a>
            </li>
          </ul>
      </li>
      <li><a href="../../../guide/topics/security/security.html">
            <span class="en">Security and Permissions</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/manifest/manifest-intro.html">
          <span class="en">The AndroidManifest.xml File</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/manifest/action-element.html">&lt;action&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/application-element.html">&lt;application&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/category-element.html">&lt;category&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/compatible-screens-element.html">&lt;compatible-screens&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/data-element.html">&lt;data&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/grant-uri-permission-element.html">&lt;grant-uri-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/instrumentation-element.html">&lt;instrumentation&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/path-permission-element.html">&lt;path-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-element.html">&lt;permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-group-element.html">&lt;permission-group&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-tree-element.html">&lt;permission-tree&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/provider-element.html">&lt;provider&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/receiver-element.html">&lt;receiver&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/service-element.html">&lt;service&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/supports-gl-texture-element.html">&lt;supports-gl-texture&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></li><!-- ##api level 4## -->
          <li><a href="../../../guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></li> <!-- ##api level 4## -->
          <li><a href="../../../guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></li>
        </ul>
      </li><!-- end of the manifest file -->
    </ul>

    <ul>
    <li class="toggle-list">
        <div><a href="../../../guide/topics/graphics/index.html">
            <span class="en">Graphics</span>
          </a><span class="new-child">new!</span></div>
        <ul>
          <li><a href="../../../guide/topics/graphics/2d-graphics.html">
              <span class="en">Canvas and Drawables</span></a></li>
          <li><a href="../../../guide/topics/graphics/hardware-accel.html">
              <span class="en">Hardware Acceleration</span></a>
            <span class="new">new!</span></li>
          <li><a href="../../../guide/topics/graphics/opengl.html">
              <span class="en">OpenGL</span>
            </a><span class="new">updated</span></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/graphics/animation.html">
            <span class="en">Animation</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/topics/graphics/prop-animation.html">
              <span class="en">Property Animation</span></a></li>
          <li><a href="../../../guide/topics/graphics/view-animation.html">
              <span class="en">View Animation</span></a></li>
          <li><a href="../../../guide/topics/graphics/drawable-animation.html">
              <span class="en">Drawable Animation</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
	        <div><a href="../../../guide/topics/renderscript/index.html">
	            <span class="en">RenderScript</span>
	          </a></div>
	        <ul>
	          <li><a href="../../../guide/topics/renderscript/graphics.html">
	                <span class="en">Graphics</span>
	              </a>
	          </li>
	          <li><a href="../../../guide/topics/renderscript/compute.html">
	                <span class="en">Compute</span>
	              </a>
	          </li>
	        </ul>
  	  </li>

      <li class="toggle-list">
          <div><a href="../../../guide/topics/media/index.html">
            <span class="en">Multimedia and Camera</span>
          </a><span class="new">updated</span></div>
          <ul>
            <li><a href="../../../guide/topics/media/mediaplayer.html">
                  <span class="en">Media Playback</span></a>
                </li>
            <li><a href="../../../guide/topics/media/jetplayer.html">
                  <span class="en">JetPlayer</span></a>
                </li>
            <li><a href="../../../guide/topics/media/camera.html">
                  <span class="en">Camera</span></a>
                  <span class="new">new!</span>
                </li>
            <li><a href="../../../guide/topics/media/audio-capture.html">
                  <span class="en">Audio Capture</span></a>
                </li>
          </ul>
      </li>
      <li>
        <a href="../../../guide/topics/clipboard/copy-paste.html">
            <span class="en">Copy and Paste</span>
        </a></li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Sensors</a></div>
          <ul>
            <li><a style="color:gray;">Camera</a></li>
            <li><a style="color:gray;">Compass</a></li>
            <li><a style="color:gray;">Accelerometer</a></li>
          </ul>
      </li> -->
      <li class="toggle-list">
        <div><a href="../../../guide/topics/location/index.html">
               <span class="en">Location and Maps</span>
             </a></div>
        <ul>
          <li><a href="../../../guide/topics/location/obtaining-user-location.html">
                <span class="en">Obtaining User Location</span>
              </a></li>
        </ul>
      </li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Wireless Controls</a></div>
          <ul>
            <li><a style="color:gray;">Wi-Fi</a></li>
          </ul>
      </li> -->
  <!--<li><a style="color:gray;">Localization</a></li>  -->
      <li><a href="../../../guide/topics/appwidgets/index.html">
            <span class="en">App Widgets</span></a>
          </li>
      <li><a href="../../../guide/topics/wireless/bluetooth.html">
            <span class="en">Bluetooth</span></a>
          </li>
      <li><a href="../../../guide/topics/nfc/index.html">
            <span class="en">Near Field Communication</span>
          </a></li>
      <li class="toggle-list">
          <div><a href="../../../guide/topics/usb/index.html">
            <span class="en">USB</span></a>
          </div>
            <ul>
              <li><a href="../../../guide/topics/usb/accessory.html">Accessory</a></li>
              <li><a href="../../../guide/topics/usb/host.html">Host</a></li>
              <li><a href="../../../guide/topics/usb/adk.html">Open Accessory Dev Kit</a></li>
            </ul>
          </li>

       <li><a href="../../../guide/topics/network/sip.html">
            <span class="en">Session Initiation Protocol</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/search/index.html">
            <span class="en">Search</span>
          </a></div>
          <ul>
            <li><a href="../../../guide/topics/search/search-dialog.html">Creating a Search Interface</a></li>
            <li><a href="../../../guide/topics/search/adding-recent-query-suggestions.html">Adding Recent Query Suggestions</a></li>
            <li><a href="../../../guide/topics/search/adding-custom-suggestions.html">Adding Custom Suggestions</a></li>
            <li><a href="../../../guide/topics/search/searchable-config.html">Searchable Configuration</a></li>
          </ul>
      </li>
      <li><a href="../../../guide/topics/admin/device-admin.html">
            <span class="en">Device Administration</span></a>
      </li>
      <li class="toggle-list">
           <div>
                <a href="../../../guide/topics/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../../guide/topics/testing/testing_android.html">
                <span class="en">Testing Fundamentals</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/activity_testing.html">
                <span class="en">Activity Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/contentprovider_testing.html">
                <span class="en">Content Provider Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/service_testing.html">
                <span class="en">Service Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/what_to_test.html">
                <span class="en">What To Test</span></a>
              </li>
           </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Android Market Topics</span>
    </h2>
    <ul>
      <li><a href="../../../guide/publishing/licensing.html">
          <span class="en">Application Licensing</span></a>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/market/billing/index.html">
            <span class="en">In-app Billing</span></a>
        </div>
        <ul>
          <li><a href="../../../guide/market/billing/billing_overview.html">
              <span class="en">In-app Billing Overview</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_integrate.html">
              <span class="en">Implementing In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_best_practices.html">
              <span class="en">Security and Design</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_testing.html">
              <span class="en">Testing In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_admin.html">
              <span class="en">Administering In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_reference.html">
              <span class="en">In-app Billing Reference</span></a>
          </li>
        </ul>
      </li>
      <li><a href="../../../guide/appendix/market-filters.html">
          <span class="en">Market Filters</span></a>
      </li>
      <li><a href="../../../guide/market/publishing/multiple-apks.html">
          <span class="en">Multiple APK Support</span></a>
      </li>
    </ul>
  </li>


  <li>
    <h2><span class="en">Developing</span>
               <span class="de" style="display:none">Entwicklung</span>
               <span class="es" style="display:none">Desarrollo</span>
               <span class="fr" style="display:none">Développement</span>
               <span class="it" style="display:none">Sviluppo</span>
               <span class="ja" style="display:none">開発</span>
               <span class="zh-CN" style="display:none">开发</span>
               <span class="zh-TW" style="display:none">開發</span>
    </h2>
    <ul>
  <!--<li><a href="">Developing for Android</a></li>
      signing, upgrading, selecting a package name, select device profile, touch, trackball, dpad available, etc. -->
      <li>
        <a href="../../../guide/developing/index.html">
        <span class="en">Introduction</span></a>
      </li>

      <li class="toggle-list">
        <div>
           <a href="../../../guide/developing/devices/index.html">
                <span class="en">Managing Virtual Devices</span>
            </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/devices/managing-avds.html">
              <span class="en">With AVD Manager</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/devices/managing-avds-cmdline.html">
              <span class="en">From the Command Line</span>
            </a>
          </li>
          <li>
           <a href="../../../guide/developing/devices/emulator.html">
                <span class="en">Using the Android Emulator</span>
            </a>
          </li>
        </ul>
      </li>
      <li>
        <a href="../../../guide/developing/device.html">
          <span class="en">Using Hardware Devices</span>
        </a>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/projects/index.html">
            <span class="en">Managing Projects</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/projects/projects-eclipse.html">
              <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/projects/projects-cmdline.html">
                <span class="en">From the Command Line</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/building/index.html">
            <span class="en">Building and Running</span>
          </a>
        </div>
        <ul>
          <li><a href="../../../guide/developing/building/building-eclipse.html">
            <span class="en">From Eclipse with ADT</span>
          </a></li>
          <li><a href="../../../guide/developing/building/building-cmdline.html">
            <span class="en">From the Command Line</span></a></li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/debugging/index.html">
            <span class="en">Debugging</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/debugging/debugging-projects.html">
                <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-projects-cmdline.html">
                <span class="en">From Other IDEs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/ddms.html">
              <span class="en">Using DDMS</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-log.html">
                <span class="en">Reading and Writing Logs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-ui.html">
                <span class="en">Debugging and Profiling UIs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-tracing.html">
                <span class="en">Profiling with Traceview and dmtracedump</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-devtools.html">
                <span class="en">Using the Dev Tools App</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
           <div>
                <a href="../../../guide/developing/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../../guide/developing/testing/testing_eclipse.html">
                  <span class="en">From Eclipse with ADT</span>
                </a>
              </li>

              <li>
                <a href="../../../guide/developing/testing/testing_otheride.html">
                  <span class="en">From Other IDEs</span>
                </a>
              </li>
           </ul>
         </li>

         <li class="toggle-list">
        <div><a href="../../../guide/developing/tools/index.html">
            <span class="en">Tools</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/developing/tools/adb.html">adb</a></li>
          <li><a href="../../../guide/developing/tools/adt.html">ADT</a></li>
          <li><a href="../../../guide/developing/tools/android.html">android</a></li>
          <li><a href="../../../guide/developing/tools/bmgr.html">bmgr</a>
          <li><a href="../../../guide/developing/tools/dmtracedump.html">dmtracedump</a></li>
          <li><a href="../../../guide/developing/tools/draw9patch.html">Draw
          9-Patch</a></li>
          <li><a href="../../../guide/developing/tools/emulator.html">Emulator</a></li>
          <li><a href="../../../guide/developing/tools/etc1tool.html">etc1tool</a></li>
          <li><a href="../../../guide/developing/tools/hierarchy-viewer.html">Hierarchy Viewer</a></li>
          <li><a href="../../../guide/developing/tools/hprof-conv.html">hprof-conv</a></li>
          <li><a href="../../../guide/developing/tools/layoutopt.html">layoutopt</a></li>
          <li><a href="../../../guide/developing/tools/logcat.html">logcat</a></li>
          <li><a href="../../../guide/developing/tools/mksdcard.html">mksdcard</a></li>
          <li><a href="../../../guide/developing/tools/monkey.html">Monkey</a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/developing/tools/monkeyrunner_concepts.html">
              <span class="en">monkeyrunner</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/developing/tools/MonkeyDevice.html">
                <span class="en">MonkeyDevice</span>
                </a></li>
              <li><a href="../../../guide/developing/tools/MonkeyImage.html">
                <span class="en">MonkeyImage</span>
                </a></li>
              <li><a href="../../../guide/developing/tools/MonkeyRunner.html">
                <span class="en">MonkeyRunner</span>
                </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/developing/tools/proguard.html">ProGuard</a></li>
          <li><a href="../../../guide/developing/tools/adb.html#sqlite">sqlite3</a></li>
          <li><a href="../../../guide/developing/tools/traceview.html">Traceview</a></li>
          <li><a href="../../../guide/developing/tools/zipalign.html">zipalign</a></li>
        </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Publishing</span>
        <span class="de" style="display:none">Veröffentlichung</span>
        <span class="es" style="display:none">Publicación</span>
        <span class="fr" style="display:none">Publication</span>
        <span class="it" style="display:none">Pubblicazione</span>
        <span class="ja" style="display:none">公開</span>
        <span class="zh-CN" style="display:none">发布</span>
        <span class="zh-TW" style="display:none">發佈</span>
    </h2>
    <ul>
      <li><a href="../../../guide/publishing/app-signing.html">
            <span class="en">Signing Your Applications</span>
            <span class="de" style="display:none">Signieren Ihrer Anwendungen</span>
            <span class="es" style="display:none">Firma de aplicaciones</span>
            <span class="fr" style="display:none">Attribution de votre signature <br />à vos applications</span>
            <span class="it" style="display:none">Firma delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションへの署名</span>
            <span class="zh-CN" style="display:none">应用程序签名</span>
            <span class="zh-TW" style="display:none">簽署應用程式</span>
          </a></li>
      <li><a href="../../../guide/publishing/versioning.html">
            <span class="en">Versioning Your Applications</span>
            <span class="de" style="display:none">Versionsverwaltung für Ihre <br />Anwendungen</span>
            <span class="es" style="display:none">Versiones de las aplicaciones</span>
            <span class="fr" style="display:none">Attribution d'une version à vos applications</span>
            <span class="it" style="display:none">Controllo versioni delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションのバージョニング</span>
            <span class="zh-CN" style="display:none">应用程序版本控制</span>
            <span class="zh-TW" style="display:none">應用程式版本設定</span>
          </a></li>
      <li><a href="../../../guide/publishing/preparing.html">
            <span class="en">Preparing to Publish</span>
            <span class="de" style="display:none">Vorbereitung auf die Veröffentlichung</span>
            <span class="es" style="display:none">Publicación de aplicaciones</span>
            <span class="fr" style="display:none">Préparation à la publication</span>
            <span class="it" style="display:none">Preparativi per la pubblicazione</span>
            <span class="ja" style="display:none">公開の準備</span>
            <span class="zh-CN" style="display:none">准备发布</span>
            <span class="zh-TW" style="display:none">準備發佈</span>
          </a></li>
      <li><a href="../../../guide/publishing/publishing.html">
            <span class="en">Publishing on Android Market</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Best Practices</span>
               <span class="de" style="display:none">Bewährte Verfahren</span>
               <span class="es" style="display:none">Prácticas recomendadas</span>
               <span class="fr" style="display:none">Meilleures pratiques</span>
               <span class="it" style="display:none">Best practice</span>
               <span class="ja" style="display:none">ベスト プラクティス</span>
               <span class="zh-CN" style="display:none">最佳实践</span>
               <span class="zh-TW" style="display:none">最佳實務</span>
    </h2>
    <ul>
      <li><a href="../../../guide/practices/compatibility.html">
            <span class="en">Compatibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/screens_support.html">
          <span class="en">Supporting Multiple Screens</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/practices/screens-distribution.html">
            <span class="en">Distributing to Specific Screens</span>
          </a></li>
          <li><a href="../../../guide/practices/screen-compat-mode.html">
            <span class="en">Screen Compatibility Mode</span>
          </a></li>
          <li><a href="../../../guide/practices/screens-support-1.5.html">
            <span class="en">Strategies for Android 1.5</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/practices/optimizing-for-3.0.html">
            <span class="en">Optimizing Apps for Android 3.0</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/ui_guidelines/index.html">
               <span class="en">UI Guidelines</span>
             </a></div>
        <ul>
          <li class="toggle-list">
            <div><a href="../../../guide/practices/ui_guidelines/icon_design.html">
                   <span class="en">Icon Design <span class="new">updated</span></span>
                 </a></div>
            <ul>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_launcher.html">
                    <span class="en">Launcher Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_menu.html">
                    <span class="en">Menu Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_action_bar.html">
                    <span class="en">Action Bar Icons <span class="new">new!</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_status_bar.html">
                    <span class="en">Status Bar Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_tab.html">
                    <span class="en">Tab Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_dialog.html">
                    <span class="en">Dialog Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_list.html">
                    <span class="en">List View Icons</span>
                  </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/practices/ui_guidelines/widget_design.html">
                <span class="en">App Widget Design <span class="new">updated</span></span>
              </a></li>
          <li><a href="../../../guide/practices/ui_guidelines/activity_task_design.html">
                <span class="en">Activity and Task Design</span>
              </a></li>
          <li><a href="../../../guide/practices/ui_guidelines/menu_design.html">
                <span class="en">Menu Design</span>
              </a></li>
        </ul>
      </li>
      </ul>
      <ul>
      <li><a href="../../../guide/practices/design/accessibility.html">
            <span class="en">Designing for Accessibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/design/performance.html">
            <span class="en">Designing for Performance</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/practices/design/jni.html">
                <span class="en">JNI Tips</span>
              </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/practices/design/responsiveness.html">
            <span class="en">Designing for Responsiveness</span>
          </a></li>
      <li><a href="../../../guide/practices/design/seamlessness.html">
            <span class="en">Designing for Seamlessness</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Web Applications</span>
    </h2>
    <ul>
      <li><a href="../../../guide/webapps/index.html">
            <span class="en">Web Apps Overview</span>
          </a></li>
      <li><a href="../../../guide/webapps/targeting.html">
            <span class="en">Targeting Screens from Web Apps</span>
          </a></li>
      <li><a href="../../../guide/webapps/webview.html">
            <span class="en">Building Web Apps in WebView</span>
          </a></li>
      <li><a href="../../../guide/webapps/debugging.html">
            <span class="en">Debugging Web Apps</span>
          </a></li>
      <li><a href="../../../guide/webapps/best-practices.html">
            <span class="en">Best Practices for Web Apps</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Appendix</span>
               <span class="de" style="display:none">Anhang</span>
               <span class="es" style="display:none">Apéndice</span>
               <span class="fr" style="display:none">Annexes</span>
               <span class="it" style="display:none">Appendice</span>
               <span class="ja" style="display:none">付録</span>
               <span class="zh-CN" style="display:none">附录</span>
               <span class="zh-TW" style="display:none">附錄</span>
    </h2>
    <ul>
      <li><a href="../../../guide/appendix/api-levels.html">
            <span class="en">Android API Levels</span>
          </a></li>
      <li><a href="../../../guide/appendix/install-location.html">
            <span class="en">App Install Location</span>
          </a></li>
      <li><a href="../../../guide/appendix/media-formats.html">
            <span class="en">Supported Media Formats <span class="new">updated</span></span>
          </a></li>
      <li><a href="../../../guide/appendix/g-app-intents.html">
            <span class="en">Intents List: Google Apps</span>
          </a></li>
      <li><a href="../../../guide/developing/tools/aidl.html">AIDL</a></li>
      <li><a href="../../../guide/appendix/glossary.html">
            <span class="en">Glossary</span>
          </a></li>
    </ul>
  </li>

</ul>

<script type="text/javascript">
<!--
    buildToggleLists();
    changeNavLang(getLangPref());
//-->
</script>

      </div>
    </div> <!-- end side-nav -->
    <script>
      addLoadEvent(function() {
        scrollIntoView("devdoc-nav");
        });
    </script>




<div class="g-unit" id="doc-content"><a name="top"></a>

<div id="jd-header" class="guide-header">
  <span class="crumb">
    
      <a href="index.html">User Interface</a> >
    
  </span>
<h1>Action Bar</h1>
</div>

  <div id="jd-content">

    <div class="jd-descr">
    <div id="qv-wrapper">
<div id="qv">

  <h2>Quickview</h2>
  <ul>
    <li>A replacement for the title bar that includes the application icon and activity title</li>
    <li>Provides action items from the Options Menu and modes of navigating around the
application</li>
    <li>Supports custom views, including an embedded search box</li>
    <li>Requires API Level 11</li>
  </ul>

  <h2>In this document</h2>
  <ol>
    <li><a href="#Adding">Adding the Action Bar</a>
      <ol>
        <li><a href="#Removing">Removing the Action Bar</a></li>
      </ol>
    </li>
    <li><a href="#ActionItems">Adding Action Items</a>
      <ol>
        <li><a href="#Home">Using the app icon as an action item</a></li>
      </ol>
    </li>
    <li><a href="#ActionView">Adding an Action View</a></li>
    <li><a href="#Tabs">Adding Tabs</a></li>
    <li><a href="#Dropdown">Adding Drop-down Navigation</a></li>
    <li><a href="#Style">Styling the Action Bar</a></li>
  </ol>

  <h2>Key classes</h2>
  <ol>
    <li><code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code></li>
    <li><code><a href="../../../reference/android/view/Menu.html">Menu</a></code></li>
  </ol>
  
  <h2>Related samples</h2>
  <ol>
    <li><a href="../../../resources/samples/ApiDemos/src/com/example/android/apis/app/index.html#ActionBar">API
        Demos</a></li>
    <li><a
href="../../../resources/samples/HoneycombGallery/index.html">Honeycomb Gallery</a></li>
  </ol>
  
  <h2>See also</h2>
  <ol>
    <li><a href="../../../guide/topics/ui/menus.html">Menus</a></li>
  </ol>
</div>
</div>

<p>The Action Bar is a widget for activities that replaces the traditional title bar at
the top of the screen. By default, the Action Bar includes the application logo on the left side,
followed by the activity title, and any available items from the Options Menu on the right side. The
Action Bar offers several useful features, including the ability to:</p>

<ul>
  <li>Display items from the <a
href="../../../guide/topics/ui/menus.html#OptionsMenu">Options Menu</a> directly in the Action
Bar, as "action
items"&mdash;providing instant access to key user actions.
    <p>Menu items that do not appear as action items are placed in the overflow menu, revealed
by a drop-down list in the Action Bar.</p></li>
  <li>Provide tabs for navigating between <a
href="../../../guide/topics/fundamentals/fragments.html">fragments</a>.</li>
  <li>Provide a drop-down list for navigation.</li>
  <li>Provide interactive "action views" in place of action items (such as a search box).</li>
</ul>

<img src="../../../images/ui/actionbar.png" height="36" alt="" />

<p class="img-caption"><strong>Figure 1.</strong> A screenshot of the Action Bar in the Email
application, containing action items to compose new email and refresh the inbox.</p>


<h2 id="Adding">Adding the Action Bar</h2>

<p>The Action Bar is included by default in all activities that target Android 3.0 or greater. More
specifically, all activities that use the new "holographic" theme include the Action Bar, and any
application that targets Android 3.0 automatically receives this theme. An application is considered
to "target" Android 3.0 when it has set either the <code>android:minSdkVersion</code> or <code>android:targetSdkVersion</code> attribute in the <a
href="../../../guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a> element to
<code>"11"</code> or greater. For example:</p>

<pre>
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.helloworld"
      android:versionCode="1"
      android:versionName="1.0"&gt;
    &lt;uses-sdk android:minSdkVersion="4"
              <b>android:targetSdkVersion="11"</b> /&gt;
    &lt;application ... &gt;
        ...
    &lt;/application&gt;
&lt;/manifest&gt;
</pre>

<p>In this example, the application requires a minimum version of API
Level 4 (Android 1.6), but it also targets API Level 11 (Android 3.0). This way, when
the application is installed on a device running Android 3.0 or greater, the system applies the
holographic theme to each activity, and thus, each activity includes the Action Bar.</p>

<p>However, if you want to use Action Bar APIs, such as to add tabs or modify Action Bar styles,
you need to set the <code>android:minSdkVersion</code> to <code>"11"</code>, so you can access the
<code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code> class.</p>


<h3 id="Removing">Removing the Action Bar</h3>

<p>If you want to remove the Action Bar for a particular activity, set the activity theme to
<code><a href="../../../reference/android/R.style.html#Theme_Holo_NoActionBar">Theme.Holo.NoActionBar</a></code>. For example:</p>

<pre>
&lt;activity android:theme="&#64;android:style/Theme.Holo.NoActionBar"&gt;
</pre>

<p class="note"><strong>Tip:</strong> If you have a custom activity theme in which you'd like to
remove the Action Bar, set the <code><a href="../../../reference/android/R.styleable.html#Theme_windowActionBar">android:windowActionBar</a></code> style property <code>false</code>. See <a href="#Style">Styling the Action
Bar</a> for more about Action Bar styles.</p>

<p>You can also hide the Action Bar at runtime by calling <code><a href="../../../reference/android/app/ActionBar.html#hide()">hide()</a></code>,
then show it again by calling <code><a href="../../../reference/android/app/ActionBar.html#show()">show()</a></code>. For example:</p>

<pre>
ActionBar actionBar = getActionBar();
actionBar.hide();
</pre>

<p>When the Action Bar hides, the system adjusts your activity content to fill all the
available screen space.</p>

<p class="note"><strong>Note:</strong> If you remove the Action Bar using a theme, then the
window will not allow the Action Bar at all, so you cannot add it at runtime&mdash;calling
<code><a href="../../../reference/android/app/Activity.html#getActionBar()">getActionBar()</a></code> will return null.</p>


<h2 id="ActionItems">Adding Action Items</h2>

<p>An action item is simply a menu item from the <a
href="../../../guide/topics/ui/menus.html#OptionsMenu">Options Menu</a> which you declare should
appear directly in the Action Bar. An action item can include an icon and/or text. If a menu
item does not appear as an action item, then the system places it in the overflow menu, which
the user can open with the menu icon on the right side of the Action Bar.</p>

<div class="figure" style="width:359px">
  <img src="../../../images/ui/actionbar-item-withtext.png" height="57" alt="" />
  <p class="img-caption"><strong>Figure 2.</strong> A screenshot from an Action Bar with two
action items and the overflow menu.</p>
</div>

<p>When the activity first starts, the system populates the Action Bar and overflow menu by calling
<code><a href="../../../reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)">onCreateOptionsMenu()</a></code> for your activity. As
discussed in the <a href="../../../guide/topics/ui/menus.html">Menus</a> developer guid, it's in
this callback method that you define the Options Menu for the activity.</p>

<p>You can specify a menu item to appear as an action item&mdash;if there is room
for it&mdash;from your <a href="../../../guide/topics/resources/menu-resource.html">menu
resource</a> by declaring <code>android:showAsAction="ifRoom"</code> for the <code>&lt;item&gt;</code> element. This way, the menu item appears
in the Action Bar for quick access only if there is room available for it. If there's not
enough room, the item is placed the overflow menu (revealed by the menu icon on the right side
of the Action Bar).</p>

<p>You can also declare a menu item to appear as an action item from your application code, by
calling <code><a href="../../../reference/android/view/MenuItem.html#setShowAsAction(int)">setShowAsAction()</a></code> on the <code><a href="../../../reference/android/view/MenuItem.html">MenuItem</a></code> and passing <code><a href="../../../reference/android/view/MenuItem.html#SHOW_AS_ACTION_IF_ROOM">SHOW_AS_ACTION_IF_ROOM</a></code>.</p>

<p>If your menu item supplies both a title and an icon, then the action item shows only
the icon by defult. If you want to include the text with the action item, add the "with
text" flag: in XML, add <code>withText</code> to the <code>android:showAsAction</code> attribute or, in
your application code, use the <code><a href="../../../reference/android/view/MenuItem.html#SHOW_AS_ACTION_WITH_TEXT">SHOW_AS_ACTION_WITH_TEXT</a></code> flag when
calling <code><a href="../../../reference/android/view/MenuItem.html#setShowAsAction(int)">setShowAsAction()</a></code>. Figure 2 shows an Action
Bar that has two action items with text and the icon for the overflow menu.</p>

<p>Here's an example of how you can declare a menu item as an action item in a <a
href="../../../guide/topics/resources/menu-resource.html">menu resource</a> file:</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android">
    &lt;item android:id="@+id/menu_save"
          android:icon="@drawable/ic_menu_save"
          android:title="@string/menu_save"
          <b>android:showAsAction="ifRoom|withText"</b> /&gt;
&lt;/menu&gt;
</pre>

<p>In this case, both the <code>ifRoom</code> and <code>withText</code> flags are set, so that when this
item appears as an action item, it includes the title text along with the icon.</p>

<p>A menu item placed in the Action Bar triggers the same callback methods as other items in the
Options Menu. When the user selects an action item, your activity receives a call to
<code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code>, passing the
item ID.</p>

<p class="note"><strong>Note:</strong> If you added the menu item from a fragment, then the
respective <code><a href="../../../reference/android/app/Fragment.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> method is called
for that fragment. However the activity gets a chance to handle it first, so the system calls <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> on the activity
before calling the fragment.</p>

<p>You can also declare an item to <em>always</em> appear as an action item,  but you should avoid
doing so, because it can create a cluttered UI if there are too many action items and they might
collide with other elements in the Action Bar.</p>

<p>For more information about menus, see the <a
href="../../../guide/topics/ui/menus.html#options-menu">Menus</a> developer guide.</p>


<h3 id="Home">Using the app icon as an action item</h3>

<p>By default, your application icon appears in the Action Bar on the left side. It also responds 
to user interaction (when the user taps it, it visually responds the same way action
items do) and it's your responsibility to do something when the user taps it.</p>

<img src="../../../images/ui/actionbar.png" height="36" alt="" />
<p class="img-caption"><strong>Figure 3.</strong> Email's Action Bar, with the
application icon on the left.</p>

<p>The normal behavior should be for your application to return to the "home" activity or the
initial state (such as when the activity hasn't changed, but fragments have changed) when the user
taps the icon. If the user is already at home or the initial state, then you don't need to do
anything.</p>

<p>When the user taps the icon, the system calls your activity's <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> method with the  <code>android.R.id.home</code> ID. So, you need to add a condition to your <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> method to listen for <code>android.R.id.home</code> and perform the appropriate action, such as start the home activity or pop recent
fragment transactions off the stack.</p>

<p>If you respond to the application icon by returning to the home activity, you should include
the <code><a href="../../../reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP">FLAG_ACTIVITY_CLEAR_TOP</a></code> flag in the <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>. With this flag, if the activity you're starting already exists in the
current task, then all activities on top of it are destroyed and it is brought to the front.
You should favor this approach, because going "home" is an action that's equivalent to "going
back" and you should usually not create a new instance of the home activity. Otherwise, you
might end up with a long stack of activities in the current task.</p>

<p>For example, here's an implementation of <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> that returns to the application's "home" activity:</p>

<pre>
&#64;Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // app icon in Action Bar clicked; go home
            Intent intent = new Intent(this, HomeActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
</pre>




<h4>Using the app icon to navigate "up"</h4>

<div class="figure" style="width:144px">
  <img src="../../../images/ui/actionbar-logo.png" height="140" alt="" />
  <p class="img-caption"><strong>Figure 4.</strong> The standard icon for the Email application
(top) and the "up" icon (bottom).</p>
</div>

<p>You can also use the application icon to provide "up" navigation for the user. This is especially
useful when your application is composed of activities that generally appear in a certain order and
you want to facilitate the ability for the user to navigate up the activity hierarchy
(regardless of how they entered the current activity).</p>

<p>The way you respond to this event is the same as when navigating home (as
discussed above, except you start a different activity, based on the current activity). All you
need to do to indicate to the user that the behavior is different is set the Action Bar to "show
home as up." You can do so by calling <code><a href="../../../reference/android/app/ActionBar.html#setDisplayHomeAsUpEnabled(boolean)">setDisplayHomeAsUpEnabled(true)</a></code> on your activity's <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code>. When you do, the
system draws your application icon with an arrow indicating the up behavior, as shown in figure
4.</p>

<p>For example, here's how you can show the application icon as an "up" action:</p>

<pre>
&#64;Override
protected void onStart() {
    super.onStart();
    ActionBar actionBar = this.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
</pre>

<p>Then, your activity should respond to the user tapping the icon, from the <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code>, by listening for the <code>android.R.id.home</code> ID (as shown above). In
this case, when navigating up, it's even more important that you use the <code><a href="../../../reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP">FLAG_ACTIVITY_CLEAR_TOP</a></code> flag in the <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>, so that
you don't create a new instance of the parent activity if one already exists.</p>




<h2 id="ActionView">Adding an Action View</h2>

<div class="figure" style="width:429px">
  <img src="../../../images/ui/actionbar-actionview.png" alt="" />
  <p class="img-caption"><strong>Figure 5.</strong> An action view with a <code><a href="../../../reference/android/widget/SearchView.html">SearchView</a></code> widget.</p>
</div>

<p>An action view is a widget that appears in the Action Bar as a substitute for an action 
item. For example, if you have an item in the Options Menu for "Search", you can add an action view
for the item that provides a <code><a href="../../../reference/android/widget/SearchView.html">SearchView</a></code> widget in the Action Bar whenever
the item is enabled as an action item.</p>

<p>When adding an action view for a menu item, it's important that you still allow the item to
behave as a normal menu item when it does not appear in the Action Bar. For example, a menu item to
perform a search should, by default, bring up the Android search dialog, but if the item is
placed in the Action Bar, the action view appears with a <code><a href="../../../reference/android/widget/SearchView.html">SearchView</a></code>
widget. Figure 4 shows an example of  the <code><a href="../../../reference/android/widget/SearchView.html">SearchView</a></code> widget in an action
view.</p>

<p>The best way to declare an action view for an item is in your <a
href="../../../guide/topics/resources/menu-resource.html">menu resource</a>, using the <code>android:actionLayout</code> or <code>android:actionViewClass</code> attribute:</p>

<ul>
  <li>The value for <code>android:actionLayout</code> must be a resource pointer to a layout file.
For example:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android">
    &lt;item android:id="@+id/menu_search"
        android:title="Search"
        android:icon="@drawable/ic_menu_search"
        android:showAsAction="ifRoom"
        <b>android:actionLayout="@layout/searchview"</b> /&gt;
&lt;/menu>
</pre>
</li>

  <li>The value for <code>android:actionViewClass</code> must be a fully-qualified class name for
the <code><a href="../../../reference/android/view/View.html">View</a></code> you want to use. For example:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android">
    &lt;item android:id="@+id/menu_search"
        android:title="Search"
        android:icon="@drawable/ic_menu_search"
        android:showAsAction="ifRoom"
        <b>android:actionViewClass="android.widget.SearchView"</b> /&gt;
&lt;/menu>
</pre></li>
</ul>

<p class="note">You must include <code>android:showAsAction="ifRoom"</code> in order for the item to
appear as an action view when room is available. If necessary, however, you can force the item to 
always appear as an action view by setting <code>android:showAsAction</code> to <code>"always"</code>.</p>

<p>Now, when the menu item is displayed as an action item, it's action view appears instead of
the icon and/or title text. However, if there's not enough room in the Action Bar, the item appears
in the overflow menu as a normal menu item and you must respond to it from the <code><a href="../../../reference/android/app/Activity.html#onOptionsItemSelected(android.view.MenuItem)">onOptionsItemSelected()</a></code> callback method.</p>

<p>When the activity first starts, the system populates the Action Bar and overflow menu by calling
<code><a href="../../../reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)">onCreateOptionsMenu()</a></code>.
After you've inflated your menu in this method, you can acquire elements in an action view
(perhaps in order to attach listeners) by calling <code><a href="../../../reference/android/view/Menu.html#findItem(int)">findItem()</a></code> with the ID of the menu item, then <code><a href="../../../reference/android/view/MenuItem.html#getActionView()">getActionView()</a></code> on
the returned <code><a href="../../../reference/android/view/MenuItem.html">MenuItem</a></code>. For example, the search widget from the above samples is
acquired like this:</p>

<pre>
&#64;Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.options, menu);
  SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
  // Set appropriate listeners for searchView
  ...
  return super.onCreateOptionsMenu(menu);
}
</pre>

<p>For more information about using the search widget, see <a
href="../../../guide/topics/search/search-dialog.html">Creating a Search Interface</a>.</p>




<h2 id="Tabs">Adding Tabs</h2>


<div class="figure" style="width:504px">
  <img src="../../../images/ui/actionbar-tabs.png" alt="" />
  <p class="img-caption"><strong>Figure 6.</strong> Screenshot of tabs in the
Action Bar, from the <a
href="../../../resources/samples/HoneycombGallery/index.html">Honeycomb Gallery</a> sample
application.</p>
</div>

<p>The Action Bar can display tabs that allow the user navigate between different fragments in the
activity. Each tab can include a title and/or an icon.</p>

<p>To begin, your layout must include a <code><a href="../../../reference/android/view/View.html">View</a></code> in which each <code><a href="../../../reference/android/app/Fragment.html">Fragment</a></code> associated with a tab is displayed. Be sure the view has an ID that you
can use to reference it from your code.</p>

<p>To add tabs to the Action Bar:</p>
<ol>
  <li>Create an implementation of <code><a href="../../../reference/android/app/ActionBar.TabListener.html">ActionBar.TabListener</a></code> to handle the
interaction events on the Action Bar tabs. You must implement all methods: <code><a href="../../../reference/android/app/ActionBar.TabListener.html#onTabSelected(android.app.ActionBar.Tab, android.app.FragmentTransaction)">onTabSelected()</a></code>, <code><a href="../../../reference/android/app/ActionBar.TabListener.html#onTabUnselected(android.app.ActionBar.Tab, android.app.FragmentTransaction)">onTabUnselected()</a></code>, and <code><a href="../../../reference/android/app/ActionBar.TabListener.html#onTabReselected(android.app.ActionBar.Tab, android.app.FragmentTransaction)">onTabReselected()</a></code>.
    <p>Each callback method passes the <code><a href="../../../reference/android/app/ActionBar.Tab.html">ActionBar.Tab</a></code> that received the
event and a <code><a href="../../../reference/android/app/FragmentTransaction.html">FragmentTransaction</a></code> for you to perform the fragment
transactions (add or remove fragments).</p>
    <p>For example:</p>
<pre>
private class MyTabListener implements ActionBar.TabListener {
    private TabContentFragment mFragment;

    // Called to create an instance of the listener when adding a new tab
    public MyTabListener(TabContentFragment fragment) {
        mFragment = fragment;
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.add(R.id.fragment_content, mFragment, null);
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(mFragment);
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // do nothing
    }

}
</pre>
  <p>This implementation of <code><a href="../../../reference/android/app/ActionBar.TabListener.html">ActionBar.TabListener</a></code> adds a constructor
that saves the <code><a href="../../../reference/android/app/Fragment.html">Fragment</a></code> associated with a tab so that each callback
can add or remove that fragment.</p>
  </li>
  <li>Get the <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code> for your activity by calling <code><a href="../../../reference/android/app/Activity.html#getActionBar()">getActionBar()</a></code> from your <code><a href="../../../reference/android/app/Activity.html">Activity</a></code>, during <code><a href="../../../reference/android/app/Activity.html#onCreate(android.os.Bundle)">onCreate()</a></code> (but be sure you do so <em>after</em> you've called
<code><a href="../../../reference/android/app/Activity.html#setContentView(android.view.View)">setContentView()</a></code>).</li>
  <li>Call <code><a href="../../../reference/android/app/ActionBar.html#setNavigationMode(int)">setNavigationMode(NAVIGATION_MODE_TABS)</a></code> to enable tab mode for the <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code>.</li>
  <li>Create each tab for the Action Bar:
    <ol>
      <li>Create a new <code><a href="../../../reference/android/app/ActionBar.Tab.html">ActionBar.Tab</a></code> by calling <code><a href="../../../reference/android/app/ActionBar.html#newTab()">newTab()</a></code> on the <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code>.</li>
      <li>Add title text and/or an icon for the tab by calling <code><a href="../../../reference/android/app/ActionBar.Tab.html#setText(int)">setText()</a></code> and/or <code><a href="../../../reference/android/app/ActionBar.Tab.html#setIcon(android.graphics.drawable.Drawable)">setIcon()</a></code>.
        <p class="note"><strong>Tip:</strong> These methods return the same <code><a href="../../../reference/android/app/ActionBar.Tab.html">ActionBar.Tab</a></code> instance, so you can chain the calls together.</p></li>
      <li>Declare the <code><a href="../../../reference/android/app/ActionBar.TabListener.html">ActionBar.TabListener</a></code> to use for the tab by passing an
instance of your implementation to <code><a href="../../../reference/android/app/ActionBar.Tab.html#setTabListener(android.app.ActionBar.TabListener)">setTabListener()</a></code>.
    </ol>
  </li>
  <li>Add each <code><a href="../../../reference/android/app/ActionBar.Tab.html">ActionBar.Tab</a></code> to the Action Bar by calling <code><a href="../../../reference/android/app/ActionBar.html#addTab(android.app.ActionBar.Tab)">addTab()</a></code> on the <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code> and passing the
<code><a href="../../../reference/android/app/ActionBar.Tab.html">ActionBar.Tab</a></code>.</li>
</ol>
<p>For example, the following code combines steps 2 - 5 to create two tabs and add them to
the Action Bar:</p>
<pre>
&#64;Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // setup Action Bar for tabs
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // remove the activity title to make space for tabs
    actionBar.setDisplayShowTitleEnabled(false);

    // instantiate fragment for the tab
    Fragment artistsFragment = new ArtistsFragment();
    // add a new tab and set its title text and tab listener
    actionBar.addTab(actionBar.newTab().setText(R.string.tab_artists)
            .setTabListener(new TabListener(artistsFragment)));

    Fragment albumsFragment = new AlbumsFragment();
    actionBar.addTab(actionBar.newTab().setText(R.string.tab_albums)
            .setTabListener(new TabListener(albumsFragment)));
}
</pre>

<p>All the behaviors that occur when a tab is selected must be defined by your <code><a href="../../../reference/android/app/ActionBar.TabListener.html">ActionBar.TabListener</a></code> callback methods. When a tab is selected, it receives a call to
<code><a href="../../../reference/android/app/ActionBar.TabListener.html#onTabSelected(android.app.ActionBar.Tab, android.app.FragmentTransaction)">onTabSelected()</a></code> and that's where you should
add the appropriate fragment to the designated view in your layout, using <code><a href="../../../reference/android/app/FragmentTransaction.html#add(android.app.Fragment, java.lang.String)">add()</a></code> with the provided <code><a href="../../../reference/android/app/FragmentTransaction.html">FragmentTransaction</a></code>. Likewise, when a tab is deselected (because another tab becomes
selected), you should remove that fragment from the layout, using <code><a href="../../../reference/android/app/FragmentTransaction.html#remove(android.app.Fragment)">remove()</a></code>.</p>

<p class="caution"><strong>Caution:</strong> You <strong>must not</strong> call <code><a href="../../../reference/android/app/FragmentTransaction.html#commit()">commit()</a></code> for these transactions&mdash;the system calls it for you
and it may throw an exception if you call it yourself. You also <strong>cannot</strong> add these
fragment transactions to the back stack.</p>

<p>If your activity is stopped, you should retain the currently selected tab with the saved state so
that when the user returns to your application, you can open the tab. When it's time to save the
state, you can query the currently selected tab with <code><a href="../../../reference/android/app/ActionBar.html#getSelectedNavigationIndex()">getSelectedNavigationIndex()</a></code>. This returns the index position of the selected
tab.</p>

<p class="caution"><strong>Caution:</strong> It's important that you save
the state of each fragment as necessary, so when the user switches fragments with the tabs,
then returns to a previous fragment, it appears the way they left. For information about saving
the state of your fragment, see the <a
href="../../../guide/topics/fundamentals/fragments.html">Fragments</a> developer guide.</p>




<h2 id="Dropdown">Adding Drop-down Navigation</h2>

<p>As another mode of navigation within your activity, you can provide a drop-down list in the
Action Bar. For example, the drop-down list can provide alternative modes for sorting the content in
the activity or switching the user's account.</p>

<!--
<div class="figure" style="width:135px">
  <img src="../../../images/ui/actionbar-dropdown.png" alt="" />
  <p class="img-caption"><strong>Figure 5.</strong> Screenshot of a drop-down navigation list in the
Action Bar.</p>
</div>
-->

<p>Here's a quick list of steps to enable drop-down navigation:</p>

<ol>
  <li>Create a <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> that provides the
list of selectable items for the drop-down and the layout to use when drawing each item in the
list.</li>
  <li>Implement <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">ActionBar.OnNavigationListener</a></code> to define the behavior when the
user selects an item from the list.</li>
  <li>Enable navigation mode for the Action Bar with <code><a href="../../../reference/android/app/ActionBar.html#setNavigationMode(int)">setNavigationMode()</a></code>. For example:
<pre>
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
</pre>
  <p class="note"><strong>Note:</strong> You should perform this during your activity's <code><a href="../../../reference/android/app/Activity.html#onCreate(android.os.Bundle)">onCreate()</a></code> method.</p>
  </li>
  <li>Then, set the callback for the drop-down list with <code><a href="../../../reference/android/app/ActionBar.html#setListNavigationCallbacks(android.widget.SpinnerAdapter, android.app.ActionBar.OnNavigationListener)">setListNavigationCallbacks()</a></code>. For example:
<pre>
actionBar.setListNavigationCallbacks(mSpinnerAdapter, mNavigationCallback);
</pre>
<p>This method takes your <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> and <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">ActionBar.OnNavigationListener</a></code>. More about these next.</p>
</li>
</ol>

<p>That's the basic setup. However, implementing the <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> and
<code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">ActionBar.OnNavigationListener</a></code> is where most of the work is done. There are many
ways you can implement these to define the functionality for your drop-down navigation and
implementing various types of <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> is beyond the scope of this
document (you should refer to the <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> class reference for more
information). However, below is a simple example for a <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> and
<code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">ActionBar.OnNavigationListener</a></code> to get you started (click the title to
reveal the sample).</p>



<div class="toggle-content closed">

  <h3 id="Spinner"><a href="#" onclick="return toggleContent(this)">
    <img src="../../../assets/images/triangle-closed.png" class="toggle-content-img" alt="" />
    Example SpinnerAdapter and OnNavigationListener
  </a></h3>

  <div class="toggle-content-toggleme">

<p><code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> is an adapter that provides data for a spinner widget,
such as the drop-down list in the Action Bar. <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> is an interface
that you can implement, but Android includes some useful implementations that you can extend, such
as <code><a href="../../../reference/android/widget/ArrayAdapter.html">ArrayAdapter</a></code> and <code><a href="../../../reference/android/widget/SimpleCursorAdapter.html">SimpleCursorAdapter</a></code>. For example, here's an easy way to create a <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code> by using <code><a href="../../../reference/android/widget/ArrayAdapter.html">ArrayAdapter</a></code> implementation, which
uses a string array as the data source:</p>

<pre>
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list,
          android.R.layout.simple_spinner_dropdown_item);
</pre>

<p>The <code><a href="../../../reference/android/widget/ArrayAdapter.html#createFromResource(android.content.Context, int, int)">createFromResource()</a></code> method takes
three parameters: the application <code><a href="../../../reference/android/content/Context.html">Context</a></code>, the resource ID for the string
array, and the layout to use for each list item.</p>

<p>A <a href="../../../guide/topics/resources/string-resource.html#StringArray">string array</a>
defined in a resource looks like this:</p>

<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;string-array name="action_list"&gt;
        &lt;item&gt;Mercury&lt;/item&gt;
        &lt;item&gt;Venus&lt;/item&gt;
        &lt;item&gt;Earth&lt;/item&gt;
    &lt;/string-array&gt;
&lt;/pre&gt;
</pre>

<p>The <code><a href="../../../reference/android/widget/ArrayAdapter.html">ArrayAdapter</a></code> returned by <code><a href="../../../reference/android/widget/ArrayAdapter.html#createFromResource(android.content.Context, int, int)">createFromResource()</a></code> is complete and ready for you
to pass it to <code><a href="../../../reference/android/app/ActionBar.html#setListNavigationCallbacks(android.widget.SpinnerAdapter, android.app.ActionBar.OnNavigationListener)">setListNavigationCallbacks()</a></code>
(in step 4 from above). Before you do, though, you need to create the <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">OnNavigationListener</a></code>.</p>


<p>Your implementation of <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">ActionBar.OnNavigationListener</a></code> is where you handle
fragment changes or other modifications to your activity when the user selects an item from the
drop-down list. There's only one callback method to implement in the listener: <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html#onNavigationItemSelected(int, long)">onNavigationItemSelected()</a></code>.</p>

<p>The <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html#onNavigationItemSelected(int, long)">onNavigationItemSelected()</a></code>
method receives the position of the item in the list and a unique item ID provided by the <code><a href="../../../reference/android/widget/SpinnerAdapter.html">SpinnerAdapter</a></code>.</p>

<p>Here's an example that instantiates an anonymous implementation of <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">OnNavigationListener</a></code>, which inserts a <code><a href="../../../reference/android/app/Fragment.html">Fragment</a></code> into the
layout container identified by <code>R.id.fragment_container</code>:</p>

<pre>
mOnNavigationListener = new OnNavigationListener() {
  // Get the same strings provided for the drop-down's ArrayAdapter
  String[] strings = getResources().getStringArray(R.array.action_list);

  &#64;Override
  public boolean onNavigationItemSelected(int position, long itemId) {
    // Create new fragment from our own Fragment class
    ListContentFragment newFragment = new ListContentFragment();
    FragmentTransaction ft = openFragmentTransaction();
    // Replace whatever is in the fragment container with this fragment
    //  and give the fragment a tag name equal to the string at the position selected
    ft.replace(R.id.fragment_container, newFragment, strings[position]);
    // Apply changes
    ft.commit();
    return true;
  }
};
</pre>

<p>This instance of <code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">OnNavigationListener</a></code> is
complete and you can now call <code><a href="../../../reference/android/app/ActionBar.html#setListNavigationCallbacks(android.widget.SpinnerAdapter, android.app.ActionBar.OnNavigationListener)">setListNavigationCallbacks()</a></code> (in step 4), passing the <code><a href="../../../reference/android/widget/ArrayAdapter.html">ArrayAdapter</a></code> and this
<code><a href="../../../reference/android/app/ActionBar.OnNavigationListener.html">OnNavigationListener</a></code>.</p>

<p>In this example, when the user selects an item from the drop-down list, a fragment is added to
the layout (replacing the current fragment in the <code>R.id.fragment_container</code> view). The
fragment added is given a tag that uniquely identifies it, which is the same string used to
identify the fragment in the drop-down list.</p>

<p>Here's a look at the <code>ListContentFragment</code> class that defines each fragment in this
example:</p>

<pre>
public class ListContentFragment extends Fragment {
    private String mText;

    &#64;Override
    public void onAttach(Activity activity) {
      // This is the first callback received; here we can set the text for
      // the fragment as defined by the tag specified during the fragment transaction
      super.onAttach(activity);
      mText = getTag();
    }

    &#64;Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // This is called to define the layout for the fragment;
        // we just create a TextView and set its text to be the fragment tag
        TextView text = new TextView(getActivity());
        text.setText(mText);
        return text;
    }
}
</pre>

  </div><!-- end toggle-content-toggleme -->

</div><!-- end toggle-content -->





<h2 id="Style">Styling the Action Bar</h2>

<p>The Action Bar is the heading for your application and a primary interaction point for users,
so you might want to modify some of its design in order to make it feel more integrated with your
application design. There are several ways you can do this if you wish.</p>

<p>For simple modifications to the <code><a href="../../../reference/android/app/ActionBar.html">ActionBar</a></code>, you can use the following
methods:</p>

<dl>
  <dt><code><a href="../../../reference/android/app/ActionBar.html#setBackgroundDrawable(android.graphics.drawable.Drawable)">setBackgroundDrawable()</a></code></dt>
  <dd>Sets a drawable to use as the Action Bar's background. The drawable should be a <a
href="../../../guide/topics/graphics/2d-graphics.html#nine-patch">Nine-patch</a> image, a <a
href="../../../guide/topics/resources/drawable-resource.html#Shape">shape</a>, or a <a
href="../../../guide/topics/resources/more-resources.html#Color">solid color</a>, so the system can
resize the drawable based on the size of the Action Bar (you should <em>not</em> use a fixed-size
bitmap image).</dd>

  <dt><code><a href="../../../reference/android/app/ActionBar.html#setDisplayUseLogoEnabled(boolean)">setDisplayUseLogoEnabled()</a></code></dt>
  <dd>Enables the use of an alternative image (a "logo") in the Action Bar, instead of the default
application icon. A logo is often a wider, more detailed image that represents the application.
When this is enabled, the system uses the logo image defined for the application (or the
individual activity) in the manifest file, with the <a
href="../../../guide/topics/manifest/application-element.html#logo"><code>android:logo</code></a>
attribute. The logo will be resized as necessary to fit the height of the Action Bar. (Best
practice is to design the logo at the same size as your application icon.)</dd>
</dl>


<p>For more complex customizations, you can use Android's <a
href="../../../guide/topics/ui/themes.html">style and theme</a> framework to restyle your Action
Bar in several ways.</p>

<p>The Action Bar has two standard themes, "dark" and "light". The dark theme is applied with
the default holographic theme, as specified by the <code><a href="../../../reference/android/R.style.html#Theme_Holo">Theme.Holo</a></code>
theme. If you want a white background with dark text, instead, you can apply the <code><a href="../../../reference/android/R.style.html#Theme_Holo_Light">Theme.Holo.Light</a></code> theme to the activity in the manifest file. For
example:</p>

<pre>
&lt;activity android:name=".ExampleActivity"
          android:theme="@android:style/Theme.Holo.Light" />
</pre>

<p>For more control, you can override either the <code><a href="../../../reference/android/R.style.html#Theme_Holo">Theme.Holo</a></code> or <code><a href="../../../reference/android/R.style.html#Theme_Holo_Light">Theme.Holo.Light</a></code> theme and apply custom
styles to certain aspects of the Action Bar. Some of the Action Bar properties you can customize
include the following:</p>

<dl>
  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_actionBarTabStyle">android:actionBarTabStyle</a></code></dt>
  <dd>Style for tabs in the Action Bar.</dd>

  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_actionBarTabBarStyle">android:actionBarTabBarStyle</a></code></dt>
  <dd>Style for the bar that appears below tabs in the Action Bar.</dd>

  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_actionBarTabTextStyle">android:actionBarTabTextStyle</a></code></dt>
  <dd>Style for the text in the tabs.</dd>

  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_actionDropDownStyle">android:actionDropDownStyle</a></code></dt>
  <dd>Style for the drop-down list used for the overflow menu and drop-down navigation.</dd>

  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_actionButtonStyle">android:actionButtonStyle</a></code></dt>
  <dd>Style for the background image used for buttons in the Action Bar.</dd>

</dl>

<p>For example, here's a resource file that defines a custom theme for the Action Bar, based on
the standard <code><a href="../../../reference/android/R.style.html#Theme_Holo">Theme.Holo</a></code> theme:</p>

<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;resources>
    &lt;!-- the theme applied to the application or activity -->
    &lt;style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
        &lt;item name="android:actionBarTabTextStyle">@style/customActionBarTabTextStyle&lt;/item>
        &lt;item name="android:actionBarTabStyle">@style/customActionBarTabStyle&lt;/item>
        &lt;item name="android:actionBarTabBarStyle">@style/customActionBarTabBarStyle&lt;/item>
    &lt;/style>

    &lt;!-- style for the tab text -->
    &lt;style name="customActionBarTabTextStyle">
        &lt;item name="android:textColor">#2966c2&lt;/item>
        &lt;item name="android:textSize">20sp&lt;/item>
        &lt;item name="android:typeface">sans&lt;/item>
    &lt;/style>

    &lt;!-- style for the tabs -->
    &lt;style name="customActionBarTabStyle">
        &lt;item name="android:background">@drawable/actionbar_tab_bg&lt;/item>
        &lt;item name="android:paddingLeft">20dp&lt;/item>
        &lt;item name="android:paddingRight">20dp&lt;/item>
    &lt;/style>

    &lt;!-- style for the tab bar -->
    &lt;style name="customActionBarTabBarStyle">
        &lt;item name="android:background">@drawable/actionbar_tab_bar&lt;/item>
    &lt;/style>
&lt;/resources>
</pre>

<p class="note"><strong>Note:</strong> In order for the tab background image to change,
depending on the current tab state (selected, pressed, unselected), the drawable resource used
must be a <a href="../../../guide/topics/resources/drawable-resource.html#StateList">state
list drawable</a>. Also be certain that your theme declares a parent theme, from which it
inherits all styles not explicitly declared in your theme.</p>

<p>You can apply your custom theme to the entire application or to individual activities in your
manifest file, like this:</p>

<pre>
&lt;application android:theme="&#64;style/CustomActionBar"
             ... />
</pre>

<p>Additionally, if you want to create a custom theme for your activity that removes the Action
Bar completely, use the following style attributes:</p>

<dl>
  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_windowActionBar">android:windowActionBar</a></code></dt>
  <dd>Set this style property <code>false</code> to remove the Action Bar.</dd>

  <dt><code><a href="../../../reference/android/R.styleable.html#Theme_windowNoTitle">android:windowNoTitle</a></code></dt>
  <dd>Set this style property <code>true</code> to also remove the traditional title bar.</dd>
</dl>
  
<p>For more information about using themes in your application, read <a
href="../../../guide/topics/ui/themes.html">Styles and Themes</a>.</p>





    </div>

  <a href="#top" style="float:right">&uarr; Go to top</a>
  
    <p><a href="index.html">&larr; Back to User Interface</a></p>
  
  </div>

<div id="footer">


  <div id="copyright">
    
  Except as noted, this content is licensed under <a
  href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</a>. 
  For details and restrictions, see the <a href="../../../license.html">
  Content License</a>.
  </div>
  <div id="build_info">
    
  Android 4.0&nbsp;r1 - 17 Oct 2011 18:17

  </div>

  <div id="footerlinks">
    
  <p>
    <a href="http://www.android.com/terms.html">Site Terms of Service</a> -
    <a href="http://www.android.com/privacy.html">Privacy Policy</a> -
    <a href="http://www.android.com/branding.html">Brand Guidelines</a>
  </p>
  </div>

</div> <!-- end footer -->

</div><!-- end doc-content -->

</div> <!-- end body-content --> 

<script type="text/javascript">
init(); /* initialize android-developer-docs.js */
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-5831155-1");
pageTracker._trackPageview();
</script>

</body>
</html>



